I notice the following syntax in Typescript.
export type feline = typeof cat;
As far as I know, type
is not a built-in basic type, nor it is an interface or class. Actually it looks more like a syntax for aliasing, which however I can't find reference to verify my guess.
So what does the above statement mean?
James Monger :
This is a type alias - it's used to give another name to a type.\nIn your example, feline will be the type of whatever cat is.\nHere's a more full fledged example:\ninterface Animal {\n legs: number;\n}\n\nconst cat: Animal = { legs: 4 };\n\nexport type feline = typeof cat;\n\nfeline will be the type Animal, and you can use it as a type wherever you like.\nconst someFunc = (cat: feline) => {\n doSomething(cat.legs);\n};\n\nexport simply exports it from the file. It's the same as doing this:\ntype feline = typeof cat;\n\nexport {\n feline\n};\n",
2017-05-19T22:32:47